package yxy.game.pm2.module.vip;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

import org.joda.time.DateTime;

import yxy.cherry.data.DataCenter;
import yxy.cherry.data.bean.privilege;
import yxy.game.pm2.bean.Privilege;

/** 特权 */
public class PrivilegeHandle {
	static public enum PrivilegeType {
		征战扫荡次数(1), 剿匪任务刷新类型(2),;

		private int number;

		private PrivilegeType(int number) {
			this.number = number;
		}

		public int getNumber() {
			return number;
		}

		static public PrivilegeType forNumber(int value) {
			switch (value) {
			case 1:
				return 征战扫荡次数;
			case 2:
				return 剿匪任务刷新类型;
			default:
				return null;
			}
		}
	}

	public Collection<Privilege> getPrivilegeByType(String playerCode, PrivilegeType type) {
		DateTime now = DateTime.now();
		Map<Integer, Privilege> all = Privilege.all(playerCode);
		ArrayList<Privilege> list = new ArrayList<>();
		for (Privilege privilegeBean : all.values()) {
			if (privilegeBean.getEndtime() != null && privilegeBean.getEndtime().isBefore(now)) {
				continue;
			}
			privilege data = DataCenter.getData(privilegeBean.getPrivilegeid(), privilege.class);
			if (PrivilegeType.forNumber(data.getType()).equals(type)) {
				list.add(privilegeBean);
			}
		}
		return list;
	}
}
